package com.longcai.piaojia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.AppointmentDetailGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class AppointmentDetailAdapter extends ArrayAdapter<AppointmentDetailGet.AppointmentEntity> {

    private Context context;
    private LayoutInflater layoutInflater;

    public AppointmentDetailAdapter(Context context, List<AppointmentDetailGet.AppointmentEntity> lists) {
        super(context, 0, lists);

        layoutInflater = LayoutInflater.from(context);

        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        AppointmentDetailGet.AppointmentEntity appointmentEntity = getItem(position);

        ViewHolder viewHolder;

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_appoint_detail_lists, null)));

            convertView.setTag(viewHolder);
        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.appoint_detail_tv.setText(appointmentEntity.title);
        viewHolder.appoint_price_tv.setText(appointmentEntity.price + "/" + appointmentEntity.attr);
        viewHolder.appoint_num_tv.setText("数量 "+ appointmentEntity.number);

        return convertView;
    }

    class ViewHolder {

        @BoundView(R.id.appoint_detail_tv) private TextView appoint_detail_tv;
        @BoundView(R.id.appoint_price_tv) private TextView appoint_price_tv;
        @BoundView(R.id.appoint_num_tv) private TextView appoint_num_tv;

    }
}
